<%@ page language="java" import="java.util.*,java.sql.*" pageEncoding="utf-8"%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>注册处理页面</title>
  </head>
  <body>
  <%  
  	String username=request.getParameter("userName");
  	String password=request.getParameter("pwd");
  	String verifycode=request.getParameter("verifycode");//提取验证码
  	String realcode=session.getAttribute("verify").toString();
  	String relatedEmail=request.getParameter("verifyEmail");
  	
  %>
  <%   if(!realcode.equals(verifycode.toString())){
  %>
  	
  	<script>alert("验证码不正确,请重新输入");
  		window.location.href="register.jsp";
  		</script>}
  		<%}
  			try{
  			 Class.forName("org.mariadb.jdbc.Driver").newInstance();  
  	  String url ="jdbc:mariadb://localhost:3306/imtshop?useUnicode=true&characterEncoding=utf-8"; 
  	  String user="root";
  	  String pwd="123456";
  	  Connection conn= DriverManager.getConnection(url,user,pwd); //连接字符串
  	  Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); 
		String sql="insert into loginuser(username,password,email) values('"+username+"','"+password+"','"+relatedEmail+"')";
		int temp=stmt.executeUpdate(sql);//执行插入语句
		if(temp>0){%>
		<script>
			alert("恭喜您注册成功，开始登录吧^_^");
			window.location.href="login.jsp";
			
		</script>
		<%} %>
			<script>
			alert("抱歉，注册失败>_<，请重新注册");
			window.location.href="register.jsp";
			
		</script>
		<%
			stmt.close();
			conn.close();
  			}
  		catch(Exception e)
  		{
  			e.printStackTrace();
  			out.print("数据库连接错误");
  			
  		}
  		
		%>
			
			
		
  				
  				
  				
  				
  		
  		
  		
  	
  
  </body>
</html>
